package com.why.amallrest.controller;

import java.util.Arrays;
import java.util.Map;

import com.why.common.utils.PageUtils;
import com.why.common.utils.Result;
import com.why.entity.ProductSkuEntity;
import com.why.service.ProductSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;





/**
 * 商品规格 每一件商品都有不同的规格，不同的规格又有不同的价格和优惠力度，规格表为此设计
 *
 * @author 夏沫止水
 * @email HeJieLin@gulimall.com
 * @date 2021-11-06 13:25:10
 */
@RestController
@RequestMapping("/productsku")
public class ProductSkuController {
    @Autowired
    private ProductSkuService productSkuService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions(":productsku:list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = productSkuService.queryPage(params);

        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    //@RequiresPermissions(":productsku:info")
    public Result info(@PathVariable("skuId") String skuId){
		ProductSkuEntity productSku = productSkuService.getById(skuId);

        return Result.ok().put("productSku", productSku);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions(":productsku:save")
    public Result save(@RequestBody ProductSkuEntity productSku){
		productSkuService.save(productSku);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions(":productsku:update")
    public Result update(@RequestBody ProductSkuEntity productSku){
		productSkuService.updateById(productSku);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions(":productsku:delete")
    public Result delete(@RequestBody String[] skuIds){
		productSkuService.removeByIds(Arrays.asList(skuIds));

        return Result.ok();
    }

}
